import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    PracticeState state, Dispatch dispatch, ViewService viewService) {
  return Card(
      color: Colors.white,
      elevation: 5.0,
      margin: new EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
      child: FlatButton(
        onPressed: () => dispatch(PracticeActionCreator.onClick()),
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                SizedBox(width: 8),
                Image.asset("assets/images/homework_done_flag.png",
                    width: 8, height: 24, fit: BoxFit.fill),
                SizedBox(width: 8),
                Text(state.title),
                Spacer(),
                Text('${state.score}分'),
                SizedBox(width: 8),
              ],
            ),
            SizedBox(height: 8),
            Divider(height: 1),
            SizedBox(height: 8),
            Container(
              padding: EdgeInsets.only(left: 14, right: 14),
              child: Text(
                (state.content ?? state.demand ?? '').replaceAll('\n', ''),
                maxLines: 3,
              ),
            ),
            SizedBox(height: 8),
            Row(
              children: <Widget>[
                SizedBox(width: 16),
                Container(
                  padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                  decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.grey),
                    borderRadius: BorderRadius.circular(4.0),
                  ),
                  child: Text(
                    GlobalState.grades[state.grade],
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
                SizedBox(width: 8),
                Container(
                  padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                  decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.grey),
                    borderRadius: BorderRadius.circular(4.0),
                  ),
                  child: Text(
                    GlobalState.types[state.articleType],
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
                SizedBox(width: 8),
                Container(
                  padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                  decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.grey),
                    borderRadius: BorderRadius.circular(4.0),
                  ),
                  child: Text(
                    '批改${state.counter}次',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ],
            ),
            SizedBox(height: 8),
            Divider(height: 1),
            SizedBox(height: 8),
            Row(
              children: <Widget>[
                Spacer(),
                Text('完成：'),
                SizedBox(width: 8),
                Text(state.ctime),
                SizedBox(width: 8),
                Image.asset("assets/images/right.png",
                    width: 16, height: 16, fit: BoxFit.fill),
                SizedBox(width: 8),
              ],
            ),
            SizedBox(height: 8)
          ],
        ),
      ));
}
